package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.UserResumeDAO;
import com.yang.doctorrecruitment.dto.WorkExperience;
import com.yang.doctorrecruitment.utils.NullChange;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


public class WorkExperienceAction extends ActionSupport {
    public WorkExperience workexperience;

    public String WorkExperience(){
        String CompanyName= NullChange.NullChange(workexperience.getCompanyName());
        String WorkDes=NullChange.NullChange(workexperience.getWorkDes());
        int WorkKind=workexperience.getWorkKind();
        int CompanyScale=workexperience.getCompanyScale();
        int CompanyKind=workexperience.getCompanyKind();
        JSONObject json=new JSONObject();
        json.put("CompanyName",CompanyName);
        json.put("WorkDes",WorkDes);
        json.put("WorkKind",WorkKind);
        json.put("CompanyScale",CompanyScale);
        json.put("CompanyKind",CompanyKind);
        String jsonString =json.toJSONString();
        //保存

        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");
        boolean res= UserResumeDAO.updataWorkExperience(jsonString,UserID);
        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        if(res){

            request.setAttribute("tipMessage",1);
            return SUCCESS;
        }else{
            request.setAttribute("tipMessage",2);
            return ERROR;
        }
    }

    public WorkExperience getWorkexperience() {
        return workexperience;
    }

    public void setWorkexperience(WorkExperience workexperience) {
        this.workexperience = workexperience;
    }
}
